package com.zfast.yugioh.controller;

import com.github.pagehelper.PageInfo;
import com.zfast.forge.common.BaseResult;
import com.zfast.forge.common.Page;
import com.zfast.forge.valid.Create;
import com.zfast.yugioh.model.Role;
import com.zfast.yugioh.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 角色
 *
 * @author zgn
 * @email 
 * @date 2022-06-11 15:07:43
 */
@RestController
@RequestMapping("api/role")
@Api(tags = {"角色Con"})
public class RoleController{
    @Resource
    RoleService roleService;

    @PostMapping({"/list"})
    @ApiOperation(value = "角色数据列表", httpMethod = "POST", notes = "获取角色列表")
    public BaseResult<PageInfo<Role>> list(@RequestBody Page<Role> page) {
        BaseResult result=BaseResult.builder()
                .msg("获取角色列表成功")
                .data(roleService.pageList(page))
                .build();
        return result;
    }

    @GetMapping({"/get/{id}"})
    @ApiOperation(value = "角色数据列表", httpMethod = "GET", notes = "获取单个角色记录")
    public BaseResult<Role> get(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("查询角色成功")
                .data(roleService.get(id))
                .build();
        return result;
    }

    @PostMapping({"add"})
    @ApiOperation(value = "新增角色信息", httpMethod = "POST", notes = "保存角色")
    public BaseResult<Integer> add(@RequestBody @Validated(Create.class) Role model) {
        BaseResult result=BaseResult.builder()
                .msg("添加角色成功")
                .data(roleService.insert(model))
                .build();
        return result;
    }

    @PostMapping({"update"})
    @ApiOperation(value = "更新指定id的 角色 信息（更新全部信息）", httpMethod = "POST", notes = "更新指定id的 角色 信息（更新全部信息）")
    public BaseResult<Integer> update(@RequestBody @ApiParam(name = "role", value = "角色业务对象", required = true) Role model) {
        BaseResult result=BaseResult.builder()
                .msg("更新角色成功")
                .data(roleService.update(model))
                .build();
        return result;
    }

    @GetMapping({"remove/{id}"})
    @ApiOperation(value = "删除角色记录", httpMethod = "GET", notes = "删除角色记录")
    public BaseResult<Integer> remove(@ApiParam(name = "id", value = "业务主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("删除角色成功")
                .data(roleService.delete(id))
                .build();
        return result;
    }
}
